
********************************************************************************************************************************
						
														***Marlene Mauk, Max Groemping***
			***Online Disinformation Predicts Inaccurate Beliefs about Election Fairness among Winners and Losers***
													***Replication File  ##0 - MASTER DO FILE***
						
********************************************************************************************************************************

** last updated: 2023-05-19 ** 

/* general instructions:
This master do file contains references to a number of sub do files for specific tasks. They can all be executed automatically from this master do file. 
NB! Please note that you cannot simply execute this entire do file at once since some in-between steps have to be run in Mplus and R. Whenever this is required, instructions are included here as a comment 
Additionally, the ReadMe.docx available on Dataverse gives detailed instructions. */

/* data acquisition
Download the required datasets from their respective providers and save all of them in your data directory:
- World Values Survey Cross-National Wave 7 v1.5, https://www.worldvaluessurvey.org/wvs.jsp
- European Values Study Cross-National Wave 5 v4.0.0, including PATCH_1.do
- World Values Survey Cross-National Wave 6 v20180912, https://www.worldvaluessurvey.org/wvs.jsp
- WhoGov within dataset v1.1, https://politicscentre.nuffield.ox.ac.uk/whogov-dataset/
- World Development Indicators, https://databank.worldbank.org/source/world-development-indicators - for instructions on what to select in the web interface, see ReadMe *** NB: Data from the WDI database may change without notice and there is no versioning, so results might differ from what we reported in the paper! *** For replication of our results, use the file wdi.csv provided on dataverse
- Varieties-of-Democracy Country-Year V-Dem Full+Others v10, https://v-dem.net/
- Perceptions of Electoral Integrity Election-Level Data PEI 7.0, v2 09-05-2019, https://www.electoralintegrityproject.com/pei

For use in robustness checks, additionally download
- Perceptions of Electoral Integrity Expert-Level Data PEI 7.0, v2 09-05-2019, https://www.electoralintegrityproject.com/pei
- National Elections Across Democracy and Autocracy v6.0, https://nelda.co/

If you use different dataset versions, you will have to adjust the file names in the do files accordingly. Variable names may also have changed (but likely did not). As data are sometimes updated in newer versions, results may also differ.

Extract the ZIP file downloaded from World Bank into your data directory. Rename the file ending in _Data.csv to wdi.csv */

ssc install logout
ssc install overlay
ssc install interflex
ssc install egenmore
ssc install labutil

/* adjust this folder path to point to your data directory */
cd [data directory]

* Step 1: Data Preparation 
do 01_datapreparation.do

* Step 2: Measurement Models and Validation
do 02_measurement.do
/* run the following input files in Mplus:
- pefdisinfo.inp
- cfa_pef_initial_model.inp (results give Table B1, Model 1)
- cfa_pef_revised_model.inp (results give Table B2, Model 2)
- cfa_disinfo.inp (between results give Table D1, Model 1)
- pei.inp
- cfa_pei_initial_model.inp (results give Table C1, Model 1)
- cfa_pei_results_model.inp (results give Table C1, Model 2)
- pei_exp.inp
- cfa_pei_expert.inp */
do 03_measurement2.do

* Step 3: Validation of Measurement Models & Descriptives
do 04_validation1.do
/* run the following input files in Mplus:
- mergeddata.inp
- d1_model5a.inp (results are Table D3, Model 5a)
- d1_model5a_sm0.inp; save plot data as d1_model5a_sm0.dat
- d1_model5a_sm1.inp; save plot data as d1_model5a_sm1.dat
- d1_model5b.inp (results are Table D3, Model 5b)
- d1_model5b_sm0.inp; save plot data as d1_model5b_sm0.dat
- d1_model5b_sm1.inp; save plot data as d1_model5b_sm1.dat */
do 05_validation2.do

* Step 4: Main analyses
/* run the following input files in Mplus:
- model1.inp (results are Table 1, Model 1)
- model2.inp (results are Table 1, Model 2); save plot data as model2.dat
- model3.inp (results are Table 1, Model 3); save plot data as model3.dat
- model4.inp (results are Table 1, Model 4)
- model4_winners.inp; save plot data as model4_winners.dat
- model4_losers.inp; save plot data as model4_losers.dat */
do 06_mainanalyses.do

* Step 5: Robustness checks
/* run the following input files in Mplus:
- rc1a_model1.inp (results are Table G1, section DV: votes being counted fairly, Model 1)
- rc1a_model2.inp (results are Table G1, section DV: votes being counted fairly, Model 2); save plot data as rc1a_model2.dat
- rc1a_model3.inp (results are Table G1, section DV: votes being counted fairly, Model 3); save plot data as rc1a_model3.dat
- rc1a_model4.inp (results are Table G1, section DV: votes being counted fairly, Model 4)
- rc1a_model4_losers.inp; save plot data as rc1a_model4_losers.dat
- rc1a_model4_winners.inp; save plot data as rc1a_model4_winners.dat
- rc1b_model1.inp (results are Table G1, section DV: opposition (not) prevented from running, Model 1)
- rc1b_model2.inp (results are Table G1, section DV: opposition (not) prevented from running, Model 2); save plot data as rc1b_model2.dat
- rc1b_model3.inp (results are Table G1, section DV: opposition (not) prevented from running, Model 3); save plot data as rc1b_model3.dat
- rc1b_model4.inp (results are Table G1, section DV: opposition (not) prevented from running, Model 4)
- rc1b_model4_losers.inp; save plot data as rc1b_model4_losers.dat
- rc1b_model4_winners.inp; save plot data as rc1b_model4_winners.dat
- rc1c_model1.inp (results are Table G1, section DV: election officials being fair, Model 1)
- rc1c_model2.inp (results are Table G1, section DV: election officials being fair, Model 2); save plot data as rc1c_model2.dat
- rc1c_model3.inp (results are Table G1, section DV: election officials being fair, Model 3); save plot data as rc1c_model3.dat
- rc1c_model4.inp (results are Table G1, section DV: election officials being fair, Model 4)
- rc1c_model4_losers.inp; save plot data as rc1c_model4_losers.dat
- rc1c_model4_winners.inp; save plot data as rc1c_model4_winners.dat
- rc1d_model1.inp (results are Table G1, section DV: rich people (not) buying elections, Model 1)
- rc1d_model2.inp (results are Table G1, section DV: rich people (not) buying elections, Model 2); save plot data as rc1d_model2.dat
- rc1d_model3.inp (results are Table G1, section DV: rich people (not) buying elections, Model 3); save plot data as rc1d_model3.dat
- rc1d_model4.inp (results are Table G1, section DV: rich people (not) buying elections, Model 4)
- rc1d_model4_losers.inp; save plot data as rc1d_model4_losers.dat
- rc1d_model4_winners.inp; save plot data as rc1d_model4_winners.dat
- rc1e_model1.inp (results are Table G1, section DV: (no) violence at the polls, Model 1)
- rc1e_model2.inp (results are Table G1, section DV: (no) violence at the polls, Model 2); save plot data as rc1e_model2.dat
- rc1e_model3.inp (results are Table G1, section DV: (no) violence at the polls, Model 3); save plot data as rc1e_model3.dat
- rc1e_model4.inp (results are Table G1, section DV: (no) violence at the polls, Model 4)
- rc1e_model4_losers.inp; save plot data as rc1e_model4_losers.dat
- rc1e_model4_winners.inp; save plot data as rc1e_model4_winners.dat 

- rc2a_model1.inp (results are Table G2, section PEI expert-level data, Model 1)
- rc2a_model2.inp (results are Table G2, section PEI expert-level data, Model 2); save plot data as rc2a_model2.dat
- rc2a_model3.inp (results are Table G2, section PEI expert-level data, Model 3); save plot data as rc2a_model3.dat
- rc2a_model4.inp (results are Table G2, section PEI expert-level data, Model 4)
- rc2a_model4_losers.inp; save plot data as rc2a_model4_losers.dat
- rc2a_model4_winners.inp; save plot data as rc2a_model4_winners.dat
- rc2b_model1.inp (results are Table G2, section NELDA_11, Model 1)
- rc2b_model2.inp (results are Table G2, section NELDA_11, Model 2); save plot data as rc2b_model2.dat
- rc2b_model3.inp (results are Table G2, section NELDA_11, Model 3); save plot data as rc2b_model3.dat
- rc2b_model4.inp (results are Table G2, section NELDA_11, Model 4)
- rc2b_model4_losers.inp; save plot data as rc2b_model4_losers.dat
- rc2b_model4_winners.inp; save plot data as rc2b_model4_winners.dat
- rc2c_model1.inp (results are Table G2, section V-Dem "Clean Elections Index", Model 1)
- rc2c_model2.inp (results are Table G2, section V-Dem "Clean Elections Index", Model 2); save plot data as rc2c_model2.dat
- rc2c_model3.inp (results are Table G2, section V-Dem "Clean Elections Index", Model 3); save plot data as rc2c_model3.dat
- rc2c_model4.inp (results are Table G2, section V-Dem "Clean Elections Index", Model 4)
- rc2c_model4_losers.inp; save plot data as rc2c_model4_losers.dat
- rc2c_model4_winners.inp; save plot data as rc2c_model4_winners.dat

- rc3a_model1.inp (results are Table G3, section IV: Government disinformation, Model 1)
- rc3a_model2.inp (results are Table G3, section IV: Government disinformation, Model 2); save plot data as rc3a_model2.dat
- rc3a_model3.inp (results are Table G3, section IV: Government disinformation, Model 3); save plot data as rc3a_model3.dat
- rc3a_model4.inp (results are Table G3, section IV: Government disinformation, Model 4)
- rc3a_model4_losers.inp; save plot data as rc3a_model4_losers.dat
- rc3a_model4_winners.inp; save plot data as rc3a_model4_winners.dat
- rc3b_model1.inp (results are Table G3, section IV: Foreign disinformation, Model 1)
- rc3b_model2.inp (results are Table G3, section IV: Foreign disinformation, Model 2); save plot data as rc3b_model2.dat
- rc3b_model3.inp (results are Table G3, section IV: Foreign disinformation, Model 3); save plot data as rc3b_model3.dat
- rc3b_model4.inp (results are Table G3, section IV: Foreign disinformation, Model 4)
- rc3b_model4_losers.inp; save plot data as rc3b_model4_losers.dat
- rc3b_model4_winners.inp; save plot data as rc3b_model4_winners.dat
- rc3c_model1.inp (results are Table G3, section IV: Partisan disinformation, Model 1)
- rc3c_model2.inp (results are Table G3, section IV: Partisan disinformation, Model 2); save plot data as rc3c_model2.dat
- rc3c_model3.inp (results are Table G3, section IV: Partisan disinformation, Model 3); save plot data as rc3c_model3.dat
- rc3c_model4.inp (results are Table G3, section IV: Partisan disinformation, Model 4)
- rc3c_model4_losers.inp; save plot data as rc3c_model4_losers.dat
- rc3c_model4_winners.inp; save plot data as rc3c_model4_winners.dat

- rc4_model1.inp (results are Table G4, Model 1)
- rc4_model2.inp (results are Table G4, Model 2); save plot data as rc4_model2.dat

- rc5_model1.inp (results are Table G5, Model 1)
- rc5_model2.inp (results are Table G5, Model 2); save plot data as rc5_model2.dat
- rc5_model3.inp (results are Table G5, Model 3); save plot data as rc5_model3.dat
- rc5_model4.inp (results are Table G5, Model 4)
- rc5_model4_losers.inp; save plot data as rc5_model4_losers.dat
- rc5_model4_winners.inp; save plot data as rc5_model4_winners.dat

- rc6_model1.inp (results are Table G6, Model 1)
- rc6_model2.inp (results are Table G6, Model 2); save plot data as rc6_model2.dat
- rc6_model3.inp (results are Table G6, Model 3); save plot data as rc6_model3.dat
- rc6_model4.inp (results are Table G6, Model 4)
- rc6_model4_losers.inp; save plot data as rc6_model4_losers.dat
- rc6_model4_winners.inp; save plot data as rc6_model4_winners.dat

- rc7_model1.inp (results are Table G7, Model 1)
- rc7_model2.inp (results are Table G7, Model 2); save plot data as rc7_model2.dat
- rc7_model3.inp (results are Table G7, Model 3); save plot data as rc7_model3.dat
- rc7_model4.inp (results are Table G7, Model 4)
- rc7_model4_losers.inp; save plot data as rc7_model4_losers.dat
- rc7_model4_winners.inp; save plot data as rc7_model4_winners.dat

- rc9_model1.inp (results are Table G9, Model 1)
- rc9_model2.inp (results are Table G9, Model 2); save plot data as rc9_model2.dat
- rc9_model3.inp (results are Table G9, Model 3); save plot data as rc9_model3.dat
- rc9_model4.inp (results are Table G9, Model 4)
- rc9_model4_losers.inp; save plot data as rc9_model4_losers.dat
- rc9_model4_winners.inp; save plot data as rc9_model4_winners.dat

- rc10_model1.inp (results are Table G10, Model 1)
- rc10_model2.inp (results are Table G10, Model 2); save plot data as rc10_model2.dat
- rc10_model3.inp (results are Table G10, Model 3); save plot data as rc10_model3.dat
- rc10_model4.inp (results are Table G10, Model 4)
- rc10_model4_losers.inp; save plot data as rc10_model4_losers.dat
- rc10_model4_winners.inp; save plot data as rc10_model4_winners.dat */
do 07_robustnesschecks.do
/* run the following R script:
- Fig5.R; produces Figure 5*/